path = '/tmp/passwd'
fr = open(path)
data = fr.read()
print(data)
data = fr.read()
print(data)
fr.close()

print('-'*30)
fr = open(path)
data = fr.read(4)
print(data)
data = fr.readline()
print(data)
data = fr.readlines()
print(data)
fr.close()

print('#'*30)
fr = open(path)
for line in fr:
    print(line, end='')
fr.close()

print('#'*30)
path = '/tmp/myfile'
fw = open(path, 'w')
fw.write('hello world!\n')
fw.flush()
fw.writelines(['2nd line.\n', 'new line.\n'])
fw.close()
fr = open(path, 'r')
print(fr.read())

print('#'*30)
path = '/tmp/passwd'
with open(path) as fr:
    print(fr.readline())

print('#'*30)
fr = open(path)
print(fr.tell())
fr.readline()
print(fr.tell())
fr.seek(0,0)
print(fr.tell(), fr.read(4))
fr.seek(4,0)
print(fr.tell(), fr.read(4))
fr.close()
